<?php
if(@$_POST['open']!='please'){
	exit;
}
session_start();
include_once("../../php/include_all.php");
?>
<div class="row-fluid sortable">
    <div class="box span12 geo-box">
        <div class="box-header well">
            <h2><i class="icon-edit"></i> Verifikasi Usulan SKPD</h2>
        </div>
        <div class="box-content">
            <div style='float: inline;'>
                Lokasi : 
                <select name="skpd" id="skpd">
                    <option value='0' selected>Pilih SKPD</option>
                    <?php
					echo musrenbang_idbidang;
                    $fpx = get_datas("select s.id_skpd, s.nama_skpd from mus_skpd s, mus_subbidangbappeda sb, mus_bidang_bappeda b where s.id_subbidangbappeda=sb.id_subbidangbappeda and b.id_bdgbapeda=sb.id_bdgbapeda and b.id_bdgbapeda=".musrenbang_idbidang);
                    foreach ($fpx as $value) {
                        echo "<option value='" . $value['id_skpd'] . "'>" . ucfirst($value['nama_skpd']) . "</option>";
                    }
                    ?>
                </select>
                <span id='alerti' style='margin-left: 13px;padding-bottom:3px;'></span>
            </div>
            <table class="table table-bordered geo-table">
                <thead>
                    <tr>
                        <td>No</td>
                        <td>Program / Kegiatan</td>                        
                        <td>Keluaran</td>
                        <td>Target</td>
                        <td>Hasil</td>						
                    </tr>
                </thead>
                <tbody id="tbody_program">

                </tbody>
            </table>

        </div>
    </div>
</div>
<div id="windowRincPro" class="modal hide fade" style="width:1140px;left:26%;" valign="midle" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <header class="modal-header">
        <a href="#" class="close" data-dismiss="modal">x</a>
        <h5>Kegiatan : <span id="titleRinc"></span></h5>
    </header>
    <form class="form-horizontal" id="prokeg">
    <div class="modal-body" id="rinc_keg">
        
            <table>
                <tbody  name="rinc_keg">

                    <tr>
                        <th width='2%'>No</th>
                        <th width='20%'>Usulan</th>
                        <th width='13%'>Lokasi</th>
                        <th width='12%'>Volume</th>
                        <th width='12%'>Apbd Prov</th>
                        <th width='12%'>Apbd Kab</th>
                        <th width='12%'>Apbd Neg</th>
                        <th width='12%'>Prioritas</th>
                        <th width='5%'>Status</th>
                    </tr>
                </tbody>
            </table>                 
    </div>
    </form>
    <div id='loading' style='z-index: 1000; border: medium none; margin: 0px; padding: 0px; width: 100%; height: 100%; top: 0px; left: 0px; background-color: #515151; opacity: 0.6; position: fixed;'></div>
</div>
<script type="text/javascript">
    var urls = 'BAPPEDA/verifikasi_BAPPEDA/verifikasi_tools.php';
    function showRincProg(a) {
        var aa = $(a);
        var di = a.name.split('_');
        var wind = $('#windowRincPro');
        $('#titleRinc').html(aa.html());
        var load = $('#loading');
        var tbl = $('#rinc_keg');
        load.removeClass().addClass('BigSnakeSpiner');

        var post = $.post(urls, {act: 'rincProg', id: di[1], bgian: di[0]});
        post.done(function(res) {
            load.css('display', 'none');            
            tbl.html(res);
            statusFunction();
            init();
        });
    }

    function init() {
        $('#skpd').change(function() {
            var idSKK = this.value;
            if (idSKK > 0) {
                var post = $.post(urls, {act: 'tmpl_program', idSk: idSKK});
                post.done(function(inc) {
                    var isi = inc.split('___');
                    if (isi.length === 2) {
                        if (isi[0] == 'ok') {
                            $('#tbody_program').html(isi[1]);
                        } else if (isi[0] == 'err') {
                            $('#alerti').removeClass().addClass('alert alert-error');
                            $('#alerti').html('Error  !!!' + isi[1]);
                            setTimeout(function() {
                                $('#alerti').removeClass();
                                //$('#alerti').html('');
                            }, 1500);
                        }
                    } else {
                        $('#alerti').removeClass().addClass('alert alert-error');
                        $('#alerti').html('Gagal Mengambil data !!!');
                        setTimeout(function() {
                            $('#alerti').removeClass();
                            $('#alerti').html('');
                        }, 1500);
                    }

                });
            }
        });
        
        $('.btn-simpan-usulan').click(function() {
            var btn = $(this);
            var load = $('#loader');
            var rslt = $('#result');
            var wind = $('#windowRincPro');

            load.addClass('spinner pull-left');
            var form = $('#prokeg');
            var data = form.serializeArray();
            var post = $.post(urls, data);            
            post.done(function(res) {
                // 0-> no data; 1-> ok; 2-> error
                var result = res.split('__');
                if (result.length == 2) {
                    if (result[0] == '1') {
                        rslt.html('<font color="green">Tersimpan...</font>');
                        setTimeout(function() {
                            rslt.html('');
                            wind.modal('hide');
                        }, 2000);                       
                    } else if (result[0] == '2') {
                        rslt.html('<font color="red">' + result[1] + '</font>');
                        load.removeClass();
                        setTimeout(function(){
                            rslt.html('');
                        },2000);
                    } else if (result[0] == '0') {
                        rslt.html('<font color="#000">Tidak ada data</font>');
                        load.removeClass();
                        setTimeout(function(){
                            rslt.html('');
                        },2000);
                    }
                } else {
                    rslt.html('<font color="red">' + res + '</font>');
                }
            });
        });
    }
    function statusFunction() {
        $('.status').change(function() {
            var icn = $('#icn_' + this.id);
            var vlue = this.value;
            
            if (vlue === '0') {
                icn.removeClass();
            } else if (vlue === '1') {
                icn.removeClass().addClass('icon-terima');
            } else if (vlue === '2') {
                icn.removeClass().addClass('icon-tolak');
            } else if (vlue === '3') {
                icn.removeClass().addClass('icon-pertimbangan');
            }
        });
               
    }
    init();
</script>